; ModuleID = 'sparse_row.ll'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
target triple = "i386-pc-linux-gnu"

%struct.MPI_Status = type { i32, i32, i32, i32, i32 }
%struct.ompi_communicator_t = type opaque
%struct.ompi_datatype_t = type opaque
%struct.ompi_predefined_communicator_t = type opaque
%struct.ompi_predefined_datatype_t = type opaque

@ompi_mpi_comm_world = external global %struct.ompi_predefined_communicator_t
@ompi_mpi_int = external global %struct.ompi_predefined_datatype_t
@ompi_mpi_float = external global %struct.ompi_predefined_datatype_t
@ompi_mpi_packed = external global %struct.ompi_predefined_datatype_t
@.str = private constant [11 x i8] c"%4.1f %2d\0A\00", align 1

define i32 @main(i32 %argc, i8** %argv) nounwind {
entry:
  %argc_addr = alloca i32, align 4
  %argv_addr = alloca i8**, align 4
  %p = alloca i32
  %my_rank = alloca i32
  %nonzeroes = alloca i32
  %position = alloca i32
  %row_number = alloca i32
  %buffer = alloca [100 x i8]
  %status = alloca %struct.MPI_Status
  %"alloca point" = bitcast i32 0 to i32
  store i32 %argc, i32* %argc_addr
  store i8** %argv, i8*** %argv_addr
  %0 = call i32 @MPI_Init(i32* %argc_addr, i8*** %argv_addr) nounwind
  %1 = call i32 @MPI_Comm_size(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %p) nounwind
  %2 = call i32 @MPI_Comm_rank(%struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), i32* %my_rank) nounwind
  %3 = load i32* %my_rank, align 4
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %bb, label %bb11

bb:                                               ; preds = %entry
  store i32 10, i32* %nonzeroes, align 4
  %5 = load i32* %nonzeroes, align 4
  %6 = mul i32 %5, 4
  %7 = call noalias i8* @malloc(i32 %6) nounwind
  %8 = bitcast i8* %7 to float*
  %9 = load i32* %nonzeroes, align 4
  %10 = mul i32 %9, 4
  %11 = call noalias i8* @malloc(i32 %10) nounwind
  %12 = bitcast i8* %11 to i32*
  br label %bb2

bb1:                                              ; preds = %bb2
  %13 = sitofp i32 %i.0 to float
  %14 = fmul float %13, 2.000000e+00
  %15 = getelementptr inbounds float* %8, i32 %i.0
  store float %14, float* %15, align 1
  %16 = mul nsw i32 %i.0, 3
  %17 = getelementptr inbounds i32* %12, i32 %i.0
  store i32 %16, i32* %17, align 1
  %18 = add nsw i32 %i.0, 1
  br label %bb2

bb2:                                              ; preds = %bb1, %bb
  %i.0 = phi i32 [ 0, %bb ], [ %18, %bb1 ]
  %19 = load i32* %nonzeroes, align 4
  %20 = icmp slt i32 %i.0, %19
  br i1 %20, label %bb1, label %bb3

bb3:                                              ; preds = %bb2
  store i32 0, i32* %position, align 4
  %nonzeroes4 = bitcast i32* %nonzeroes to i8*
  %buffer5 = bitcast [100 x i8]* %buffer to i8*
  %21 = call i32 @MPI_Pack(i8* %nonzeroes4, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), i8* %buffer5, i32 100, i32* %position, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %row_number6 = bitcast i32* %row_number to i8*
  %buffer7 = bitcast [100 x i8]* %buffer to i8*
  %22 = call i32 @MPI_Pack(i8* %row_number6, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), i8* %buffer7, i32 100, i32* %position, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %23 = load i32* %nonzeroes, align 4
  %24 = bitcast float* %8 to i8*
  %buffer8 = bitcast [100 x i8]* %buffer to i8*
  %25 = call i32 @MPI_Pack(i8* %24, i32 %23, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), i8* %buffer8, i32 100, i32* %position, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %26 = load i32* %nonzeroes, align 4
  %27 = bitcast i32* %12 to i8*
  %buffer9 = bitcast [100 x i8]* %buffer to i8*
  %28 = call i32 @MPI_Pack(i8* %27, i32 %26, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), i8* %buffer9, i32 100, i32* %position, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %29 = load i32* %position, align 4
  %buffer10 = bitcast [100 x i8]* %buffer to i8*
  %30 = call i32 @MPI_Send(i8* %buffer10, i32 %29, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_packed to %struct.ompi_datatype_t*), i32 1, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  br label %bb21

bb11:                                             ; preds = %entry
  %buffer12 = bitcast [100 x i8]* %buffer to i8*
  %31 = call i32 @MPI_Recv(i8* %buffer12, i32 100, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_packed to %struct.ompi_datatype_t*), i32 0, i32 0, %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*), %struct.MPI_Status* %status) nounwind
  store i32 0, i32* %position, align 4
  %buffer13 = bitcast [100 x i8]* %buffer to i8*
  %nonzeroes14 = bitcast i32* %nonzeroes to i8*
  %32 = call i32 @MPI_Unpack(i8* %buffer13, i32 100, i32* %position, i8* %nonzeroes14, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %buffer15 = bitcast [100 x i8]* %buffer to i8*
  %row_number16 = bitcast i32* %row_number to i8*
  %33 = call i32 @MPI_Unpack(i8* %buffer15, i32 100, i32* %position, i8* %row_number16, i32 1, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %34 = load i32* %nonzeroes, align 4
  %35 = mul i32 %34, 4
  %36 = call noalias i8* @malloc(i32 %35) nounwind
  %37 = bitcast i8* %36 to float*
  %38 = load i32* %nonzeroes, align 4
  %39 = mul i32 %38, 4
  %40 = call noalias i8* @malloc(i32 %39) nounwind
  %41 = bitcast i8* %40 to i32*
  %42 = load i32* %nonzeroes, align 4
  %buffer17 = bitcast [100 x i8]* %buffer to i8*
  %43 = bitcast float* %37 to i8*
  %44 = call i32 @MPI_Unpack(i8* %buffer17, i32 100, i32* %position, i8* %43, i32 %42, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_float to %struct.ompi_datatype_t*), %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  %45 = load i32* %nonzeroes, align 4
  %buffer18 = bitcast [100 x i8]* %buffer to i8*
  %46 = bitcast i32* %41 to i8*
  %47 = call i32 @MPI_Unpack(i8* %buffer18, i32 100, i32* %position, i8* %46, i32 %45, %struct.ompi_datatype_t* bitcast (%struct.ompi_predefined_datatype_t* @ompi_mpi_int to %struct.ompi_datatype_t*), %struct.ompi_communicator_t* bitcast (%struct.ompi_predefined_communicator_t* @ompi_mpi_comm_world to %struct.ompi_communicator_t*)) nounwind
  br label %bb20

bb19:                                             ; preds = %bb20
  %48 = getelementptr inbounds i32* %41, i32 %i.1
  %49 = load i32* %48, align 1
  %50 = getelementptr inbounds float* %37, i32 %i.1
  %51 = load float* %50, align 1
  %52 = fpext float %51 to double
  %53 = call i32 (i8*, ...)* @printf(i8* noalias getelementptr inbounds ([11 x i8]* @.str, i32 0, i32 0), double %52, i32 %49) nounwind
  %54 = add nsw i32 %i.1, 1
  br label %bb20

bb20:                                             ; preds = %bb19, %bb11
  %i.1 = phi i32 [ 0, %bb11 ], [ %54, %bb19 ]
  %55 = load i32* %nonzeroes, align 4
  %56 = icmp slt i32 %i.1, %55
  br i1 %56, label %bb19, label %bb21

bb21:                                             ; preds = %bb20, %bb3
  %57 = call i32 @MPI_Finalize() nounwind
  br label %return

return:                                           ; preds = %bb21
  ret i32 undef
}

declare i32 @MPI_Init(i32*, i8***)

declare i32 @MPI_Comm_size(%struct.ompi_communicator_t*, i32*)

declare i32 @MPI_Comm_rank(%struct.ompi_communicator_t*, i32*)

declare noalias i8* @malloc(i32) nounwind

declare i32 @MPI_Pack(i8*, i32, %struct.ompi_datatype_t*, i8*, i32, i32*, %struct.ompi_communicator_t*)

declare i32 @MPI_Send(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*)

declare i32 @MPI_Recv(i8*, i32, %struct.ompi_datatype_t*, i32, i32, %struct.ompi_communicator_t*, %struct.MPI_Status*)

declare i32 @MPI_Unpack(i8*, i32, i32*, i8*, i32, %struct.ompi_datatype_t*, %struct.ompi_communicator_t*)

declare i32 @printf(i8* noalias, ...) nounwind

declare i32 @MPI_Finalize()
